using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fated.SaveEngine;

namespace Fated.Character {
    internal class PreviousClasses : IJSON {
        private List<CharacterClass> data = new List<CharacterClass>();
        public PreviousClasses() { }
        public PreviousClasses(Dictionary<string, object> input) {
            foreach (object i in input)
                data.Add(new CharacterClass((Dictionary<String, Object>)i));
        }

        public void AddClass(string name) {
            foreach (CharacterClass c in data) {
                if (c.Name.CompareTo(name) == 0) return;
            }
            data.Add(new CharacterClass(name));
        }
        public void removeClass(string name) {
            foreach (CharacterClass c in data) {
                if (c.Name.CompareTo(name) == 0) {
                    data.Remove(c);
                    break;
                }
            }
        }
        public CharacterClass getClass(string name) {
            foreach (CharacterClass c in data) {
                if (c.Name.CompareTo(name) == 0) {
                    return c;
                }
            }
            throw new Exception("Invalid Character Class");
        }
        public bool containsClass(string name) {
            foreach (CharacterClass c in data) {
                if (c.Name.CompareTo(name) == 0) {
                    return true;
                }
            }
            return false;
        }
        public int bonusHealth() {
            float output = 0;
            foreach (CharacterClass p in data) {
                output += p.ExperienceSpent / 100 * p.Health;
            }
            return (int)output;
        }
        public int bonusMagic() {
            float output = 0;
            foreach (CharacterClass p in data) {
                output += p.ExperienceSpent / 100 * p.Magic;
            }
            return (int)output;
        }
        public int bonusBody() {
            float output = 0;
            foreach (CharacterClass p in data) {
                output += p.ExperienceSpent / 100 * p.Body;
            }
            return (int)output;
        }
        public int bonusMind() {
            float output = 0;
            foreach (CharacterClass p in data) {
                output += p.ExperienceSpent / 100 * p.Mind;
            }
            return (int)output;
        }
        public int bonusSpirit() {
            float output = 0;
            foreach (CharacterClass p in data) {
                output += p.ExperienceSpent / 100 * p.Spirit;
            }
            return (int)output;
        }
        public int bonusSocial() {
            float output = 0;
            foreach (CharacterClass p in data) {
                output += p.ExperienceSpent / 100 * p.Social;
            }
            return (int)output;
        }
        public int bonusSpeed() {
            float output = 0;
            foreach (CharacterClass p in data) {
                output += p.ExperienceSpent / 100 * p.Speed;
            }
            return (int)output;
        }

        public Dictionary<string, object> ToJSON() {
            Dictionary<string, object> output = new Dictionary<string,object>();
            foreach (CharacterClass c in data) {
                output.Add(c.Name, c.ToJSON());
            }
            return output;
        }
    }
}
